<template>
	<view>
		<u-sticky><u-tabs :list="list1" active-color="rgb(241,158,194)" :is-scroll="false" :current="current" @change="change"></u-tabs></u-sticky>

		<view class="box flex" style="background: url(../../static/diary/bg.png);background-size: 100% 100%;height: calc(100vh - 88rpx);">
			<view class="w50" style="height: 180px;padding: 10px;" v-for="(item, index) in list">
				<view style="width: 100%;height: 100%;background: #fff;border-radius: 20px;overflow: hidden;text-align: center;position: relative;display: flex;align-items: center;justify-content: center;">
					<image :src="item.cover_image" mode="widthFix" style="width: 70%;margin: auto;"></image>
					<view v-if="type == 1" @click="huikui(item)" style="border-radius: 50rpx;font-size: 20rpx;position: absolute;z-index: 1;width: 40%;line-height: 30px;bottom: 10rpx;left: 10rpx;background: rgba(248, 182, 202, .5);">
						送给Ta
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			type: '',
			page: 1,
			limit: 10,
			list: [],
			list1: [
				{
					name: '我的礼物'
				},
				{
					name: '礼物中心'
				}
			],
			current: 0
		};
	},
	onLoad(e) {
		uni.setNavigationBarColor({
			frontColor: '#000000',
			backgroundColor: '#ffffff'
		});
		this.type = e.type;
		if (e.type == 1) {
			this.gift();
		} else {
			this.my_gifts();
		}
	},
	methods: {
		change(e) {
			this.current = e;
			this.type = e;
			if (e == 1) {
				this.gift();
			} else {
				this.my_gifts();
			}
		},
		huikui(e) {
			// if(this.type!=2){
			// 	uni.navigateTo({
			// 		url:'/pages/liwu/liwu?type=2'
			// 	})
			// }
			let self = this;

			if (self.current == 0) {
				self.current == 1;
			}

			if (self.current == 1) {
				uni.showModal({
					title: '提示',
					content: '确认送出礼物吗',
					success: function(res) {
						if (res.confirm) {
							let data = {
								gift_id: e.id,
								my_space_id: self.vuex_user_content.id
							};
							self.$u.api.setgive(data).then(res => {
								uni.showToast({
									title: '送出成功，快通知TA领取吧',
									duration: 2000
								});
								setTimeout(function() {
									uni.switchTab({
										url: '/pages/women/women'
									});
								}, 1800);
							});
						} else if (res.cancel) {
							uni.showToast({
								title: '已取消',
								duration: 2000
							});
						}
					}
				});
			}
			// this.current=1
		},
		async my_gifts() {
			let res = await this.$u.api.my_gifts();
			this.list = res;
		},
		async gift() {
			let res = await this.$u.api.gift();
			this.list = res;
		}
	}
};
</script>

<style>
page {
	background: #f0f0f0;
}
</style>
